package models

import (
    "github.com/astaxie/beego/orm"
    "time"
)

func (adminUser *AdminUser) TableName() string {
    return "admin_user"
}

//AdminUser实体类
type AdminUser struct{
    Id  uint
    Username string `orm:"size(60)"description:"用户名"`
    Password string `orm:"size(120)"description:"密码"`
    Sex uint8 `valid:"Min(0)";description:"性别0=未知1=男2=女"`
    Phone string `description:"手机号码"`
    Email string `description:"邮箱"`
    HeadPortrait string `description:"用户头像"`
    Status uint8 `orm:"default(1)" description:"状态1=正常2=禁用"`
    UpdatedAt time.Time `orm:"null;auto_now;type(datetime)"description:"更新时间"`
    CreatedAt time.Time `orm:"auto_now_add;type(datetime)"description:"创建时间"`
    AdminGroup []*AdminGroup `orm:"reverse(many)"`
}


//根据用户名和密码获取单条数据
func AdminUserGetUserOneByNameAndPwd(username,password string) (*AdminUser, error){
    m := AdminUser{}
    err := orm.NewOrm().QueryTable("admin_user").Filter("username",username).Filter("password",password).One(&m)
    if err != nil{
        return nil, err
    }
    return &m, nil
}

